package com.wq.payunion.oauth2.useroauth2.model.common;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: wangqiang20995
 * @Date:2018 年 9 月 16 日 0016
 * @Description:
 * @Resource:
 */
public class CommonResult {
    private String requestStatus;
    private String requestMessage;
    private ServiceResult serviceResult;

    public static final String SUCCESS_REQUEST_STATUS = "0000";
    public static final String FAILED_REQUEST_STATUS = "9999";
    public static final String SUCCESS_REQUEST_MESSAGE = "interface call successfully";
    public static final String FAILED_REQUEST_MESSAGE = "pre check error and doesn't do service";

    public static final String SUCCESS_SERVICE_STATUS = "000000";
    public static final String FAILED_SERVICE_STATUS = "999999";
    public static final String SUCCESS_SERVICE_MESSAGE = "service call successfully";

    public CommonResult(){
        this.serviceResult = new ServiceResult();
    }

    public String getRequestStatus() {
        return requestStatus;
    }

    public void setRequestStatus(String requestStatus) {
        this.requestStatus = requestStatus;
    }

    public String getRequestMessage() {
        return requestMessage;
    }

    public void setRequestMessage(String requestMessage) {
        this.requestMessage = requestMessage;
    }

    public void setServiceStatus(String status){
        this.serviceResult.setServiceStatus(status);
    }

    public void setServiceMessage(String message){
        this.serviceResult.setServiceMessage(message);
    }

    public void setServiceResponse(Map<String,Object> response){
        this.serviceResult.setResponses(response);
    }

    public void setServiceResult(String key,Object value){
        this.serviceResult.getResponses().put(key,value);
    }

//    public Map<String,Object> getServiceResponse(){
//        return this.serviceResult.getResponses();
//    }

    public Object getServiceResponse(String key){
        return this.serviceResult.getResponses().get(key);
    }

    public ServiceResult getServiceResult() {
        return serviceResult;
    }

    public void removeServiceResultByKey(String key){
        this.serviceResult.getResponses().remove(key);
    }

    @Override
    public String toString() {
        return "CommonResult{" +
                "requestStatus='" + requestStatus + '\'' +
                ", requestMessage='" + requestMessage + '\'' +
                ", serviceResult=" + serviceResult +
                '}';
    }

    private class ServiceResult{
        private String serviceStatus;
        private String serviceMessage;

        private Map<String,Object> responses;

        public ServiceResult(){
            this.responses = new HashMap<>();
        }

        public Map<String, Object> getResponses() {
            return responses;
        }

        public void setResponses(Map<String, Object> responses) {
            this.responses = responses;
        }

        public String getServiceStatus() {
            return serviceStatus;
        }

        public void setServiceStatus(String serviceStatus) {
            this.serviceStatus = serviceStatus;
        }

        public String getServiceMessage() {
            return serviceMessage;
        }

        public void setServiceMessage(String serviceMessage) {
            this.serviceMessage = serviceMessage;
        }

        @Override
        public String toString() {
            return "ServiceResult{" +
                    "serviceStatus='" + serviceStatus + '\'' +
                    ", serviceMessage='" + serviceMessage + '\'' +
                    ", responses=" + responses +
                    '}';
        }
    }
}
